#include<bits/stdc++.h>
#define y1 Y1
#define fi first
#define endl "\n"
#define se second
#define PI acos(-1)
#define int long long
#define pb(x) push_back(x)
#define PII pair<int, int>
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define _for(i, a, b) for(int i = a; i <= b; ++i)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;

const int N = 2e5 + 10;
const int mod = 1e9 + 7;

int n, m, t, ret;
string s[N];
int dir[4][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};
int dy, bz;
map<PII, int>mp;
bool flag = false;

bool check(int x, int y) {
	return x >= 1 && x <= n && y >= 1 && y <= m && s[x][y] >= '1' && mp[{x, y}] == 0;
}

void dfs(int x, int y) {
	if(s[x][y] > '1') flag = true;
	mp[{x, y}] ++ ;
	for(int i = 0; i < 4; ++ i ) {
		int dx = x + dir[i][0];
		int dy = y + dir[i][1];
		if(check(dx, dy)) {
			dfs(dx, dy);
		}
	}
}

signed main() {
	IOS;
	cin >> n >> m;
	for(int i = 1; i <= n; ++ i ) {
		string s1;
		
		cin >> s1;
		s1 = " " + s1;
		s[i] = s1;
	}
	
	for(int i = 1; i <= n; ++ i ) {
		for(int j = 1; j <= m; ++ j ) {
			if(check(i, j)) {
				dy ++ ;
				dfs(i, j);
				if(flag) {
					flag = false;
					bz ++ ;
				}
			}
		}
	}
	cout << dy << " " << bz << endl;
	return 0;
}


